package com.soyikeji.work.work.Chart.widget;

import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.util.AttributeSet;
import android.widget.ImageView;

/**
 * Created by Administrator on 2016/11/16.
 * 对主页面的交流图标进行自定义控件
 */

public class MyChartview extends ImageView {
    public static final int  ModeOne = 0;//啥也不画
    public static final int  ModeTwo = 1;//在右上角话圆圈；
    public static final int  ModeThree = 3;
    //新消息的数目
    private int num=0;
    private int mode=0;

    public MyChartview(Context context) {
        super(context);
    }

    public MyChartview(Context context, AttributeSet attrs) {
        super(context, attrs);
    }

    //提供设置模式的方法
    public void  setMode(int mode){
        this.mode = mode;
        invalidate(); //刷新屏幕：再次调用onDwaw（）方法
    }
    public  void  setNum(int num){
        this.num = num;
        invalidate();

    }

    @Override
    protected void onDraw(Canvas canvas) {
        super.onDraw(canvas);
        //创建圆形的画笔；
        Paint ciclePaint = new Paint();
        ciclePaint.setAntiAlias(true);//去掉毛边；
        ciclePaint.setColor(Color.RED);

        //创建数字的画笔
        Paint textPaint =  new Paint();
        textPaint.setColor(Color.WHITE);
        textPaint.setAntiAlias(true);
        textPaint.setTextSize(22);//太大需要修改；

        switch (mode){
            case  ModeOne:
                break;
            case ModeTwo:
                float x = getWidth() -getPaddingRight()-45;//圆心x坐标,x坐标是负数；负数是往左移动；
                float y = getPaddingTop()+19;//圆心的y坐标；负数是向上
                //getPaddingTop():圆心y坐标
                canvas.drawCircle(x,y,17,ciclePaint);
                canvas.drawText(
                        num+"",
                        (float)(x-0.5*textPaint.measureText(num+"")),
                        (float)(y+1.3*textPaint.getFontMetrics().bottom),
                        textPaint
                );

                break;
            case ModeThree:
                float x1 = getWidth() -getPaddingRight()-45;//圆心x坐标,x坐标是负数；负数是往左移动；
                float y1= getPaddingTop()+17;//圆心的y坐标；负数是向上
                //getPaddingTop():圆心y坐标
                canvas.drawCircle(x1,y1,17,ciclePaint);
                canvas.drawText(
                        99+"+",
                        (float)(x1-0.5*textPaint.measureText(99+"+")),
                        (float)(y1+1.45*textPaint.getFontMetrics().bottom),
                        textPaint
                );
                break;

        }
    }



}
